//package org.example.test2;
//
//import io.netty.buffer.ByteBuf;
//import io.netty.buffer.Unpooled;
//import io.netty.handler.codec.http.*;
//import io.netty.util.CharsetUtil;
//import reactor.core.publisher.Mono;
//import reactor.netty.http.server.HttpServer;
//import reactor.netty.http.server.HttpServerRequest;
//import reactor.netty.http.server.HttpServerResponse;
//
//public class WebServer {
//    public static void main(String[] args) {
//        HttpServer.create()
//                .port(8080)
//                .route(routes -> routes
//                        .get("/hello", (request, response) -> handleHello(request, response).then())
//                        .post("/user", (request, response) -> handleCreateUser(request, response).then())
//                )
//                .bindNow()
//                .onDispose()
//                .block();
//    }
//
//    private static Mono<FullHttpResponse> handleHello(HttpServerRequest request, HttpServerResponse response) {
//        // 构造响应内容
//        ByteBuf content = Unpooled.copiedBuffer("Hello, World!", CharsetUtil.UTF_8);
//
//        // 构建完整的HTTP响应
//        FullHttpResponse httpResponse = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, content);
//        httpResponse.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain");
//        httpResponse.headers().set(HttpHeaderNames.CONTENT_LENGTH, content.readableBytes());
//
//        return response.sendString(Mono.just(httpResponse));
//    }
//
//    private static Mono<Object> handleCreateUser(HttpServerRequest request, HttpServerResponse response) {
//        return request.receive()
//                .aggregate()
//                .asString()
//                .flatMap(payload -> {
//                    // 解析请求体中的用户信息并创建用户
//                    // TODO: 处理创建用户的逻辑
//
//                    // 返回创建的用户信息
//                    return response.status(HttpResponseStatus.CREATED)
//                            .header(HttpHeaderNames.CONTENT_TYPE, "text/plain")
//                            .sendString(Mono.just("User created successfully"));
//                });
//    }
//}
